package com.xuan.webwork.controller;

import java.util.List;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.xuan.webwork.entitys.Student;
import com.xuan.webwork.service.studentSevice;

@Controller
@RequestMapping("/students")
public class studentController {
    
    private final studentSevice studentService;

    public studentController(studentSevice studentService) {
        this.studentService = studentService;
    }
     @GetMapping("/list")
    public String listStudents(Model model) {
        List<Student> students = studentService.getAllStudents();
        model.addAttribute("students", students);
        return "student-list";
    }
    
    @GetMapping("/api/all")
    public List<Student> getAllStudents() {
        return studentService.getAllStudents();
    }
}
